package com.cy.pj.sys.service.impl;

import com.cy.pj.common.annotation.RequiredLog;
import com.cy.pj.common.exception.ServiceException;
import com.cy.pj.common.pojo.PageObject;
import com.cy.pj.common.utils.AssertUtils;
import com.cy.pj.sys.dao.SysOrderDao;
import com.cy.pj.sys.dao.SysUserDao;
import com.cy.pj.sys.dao.SysUserRoleDao;
import com.cy.pj.sys.pojo.SysOrder;
import com.cy.pj.sys.pojo.SysOrderState;
import com.cy.pj.sys.pojo.SysUser;
import com.cy.pj.sys.pojo.SysUserDept;
import com.cy.pj.sys.service.SysOrderService;
import com.cy.pj.sys.service.SysUserService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.crypto.hash.SimpleHash;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.thymeleaf.util.StringUtils;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;


@Service
public class SysOrderServiceImpl implements SysOrderService {

    @Autowired
    private SysOrderDao sysOrderDao;


    @Override
    public PageObject<SysOrderState> findPageObjects(String name, Long pageCurrent) {

        AssertUtils.isValid(pageCurrent==null || pageCurrent<1,"当前页码值无效");

        int pageSize=3;
        //设置查询位置以及页面大小
        Page<SysUser> page= PageHelper.startPage(pageCurrent.intValue(),pageSize);
        //查询当前页数据
        List<SysOrderState> records=
                sysOrderDao.findPageObjects(name);

        return new PageObject<>(page.getTotal(), records, pageSize, pageCurrent);
}

    @Override
    public Map<String, Object> findObjectById(Integer orderId) {
        //long t1=System.currentTimeMillis();//直接在雷芳芳中添加代码会违背开闭原则
        AssertUtils.isValid(orderId==null || orderId<=0,"参数数据不合法，orderId="+orderId);
        SysOrderState order=sysOrderDao.findObjectById(orderId);

        AssertUtils.isServiceValid(order==null, "此用户已经不存在");



        Map<String,Object> map=new HashMap<>();
        map.put("order", order);

        //long t2=System.currentTimeMillis();
        //log.info("time{}", t2-t1);
        return map;
    }


    @Override
    public int updateObject(SysOrder sysOrder) {

        AssertUtils.isValid(sysOrder==null, "保存对象不能为空");
        AssertUtils.isValid(StringUtils.isEmpty(sysOrder.getName()),"用户名不能为空");

        //更新用户自身信息
        int rows=sysOrderDao.updateObject(sysOrder);


        return rows;
    }



}
